<cfcomponent accessors="true" output="false">

<cfproperty name="entityName" type="string" />

<!---
list( orderBy : String, orderDir : String, criteria : Struct, maxRows : Numeric )
getById( id )
delete( id or instance ) // accepts a numeric ID or an instance, immediately doing an id = instance.getId()
save( project )
--->

<cffunction name="list" returntype="array" access="public" output="false">
	<cfargument name="orderBy" default="id" />
	<cfargument name="orderDir" default="asc" />
	<cfargument name="criteria" default="#structNew()#" />
	<cfargument name="maxRows" default="100000" />
	
	<cfreturn ormExecuteQuery( "from #variables.entityName#") />
</cffunction>

<cffunction name="get" returntype="any" access="public" output="false">
	<cfargument name="id" />
	<cfif len( arguments.id )>
		<cfreturn entityLoadByPK( variables.entityName, arguments.id) />
	</cfif>
</cffunction>

<cffunction name="count" returntype="numeric" access="public" output="false">
	<cfargument name="whereClause" type="string" required="false" default=""/>
	<cfreturn ormExecuteQuery("select count(id) from #variables.entityName# #arguments.whereClause#", true)>
</cffunction>

<cffunction name="save" returntype="any" access="public" output="false">
	<cfargument name="entity" />
	<cfset entitySave( entity ) />
	<cfreturn entity />
</cffunction>

<cffunction name="delete" returntype="void" access="public" output="false">
	<cfargument name="entityOrId" />

	<cfif not isObject( arguments.entityOrId )>
		<cfset arguments.entityOrId = get( arguments.entityOrId ) />
	</cfif>

	<cfset entityDelete( arguments.entityOrId ) />
</cffunction>

<cffunction name="createCfSqlType" returntype="string" access="public" output="false">
	<cfargument name="value" type="any" />
	
	<cfif isDate( arguments.value )>
		<cfreturn "cf_sql_timestamp" />
	<cfelseif isNumeric( arguments.value ) and round( arguments.value ) eq arguments.value>
		<cfreturn "cf_sql_integer" />
	<cfelseif isNumeric( arguments.value )>
		<cfreturn "cf_sql_float" />
	<cfelse>
		<cfreturn "cf_sql_varchar" />
	</cfif>
</cffunction>
	

</cfcomponent>